﻿@using AntDesign.Core.Extensions;
@using System.ComponentModel;
<Table Resizable TItem="Data" DataSource="@data">

    <GenerateColumns Range="1.." Definitions=definitions />

    <ActionColumn Title="Action">
        <Space Size=@("middle")>
            <SpaceItem>
                <a>Invite @context.Name</a>
            </SpaceItem>
            <SpaceItem>
                <a>Delete</a>
            </SpaceItem>
        </Space>
    </ActionColumn>
</Table>

@code {
    Data[] data = new Data[]

    {
        new()
        {
            Key = "1",
            Name = "John Brown",
            Age = 32,
            Address = "New York No. 1 Lake Park",
            Tags = new[] {"nice", "developer"}
        },
        new()
        {
            Key = "2",
            Name = "Jim Green",
            Age = 42,
            Address = "London No. 1 Lake Park",
            Tags = new[] { "loser"}
        },
        new()
        {
            Key = "3",
            Name = "Joe Black",
            Age = 32,
            Address = "Sidney No. 1 Lake Park",
            Tags = new[] { "cool", "teacher" }
        }

    };



    public class Data

    {

        [DisplayName("Key")]

        public string Key { get; set; }



        [DisplayName("Name")]

        public string Name { get; set; }



        [DisplayName("Age")]

        public int Age { get; set; }



        [DisplayName("Address")]

        public string Address { get; set; }



        [DisplayName("Tags")]

        public string[] Tags { get; set; }

    }



    /// <summary>
    /// An Action to defined each column
    /// </summary>
    /// <param name="propertyName">The name of the property binding the column. </param>
    /// <param name="column">The column instance, you need to explicitly cast to a concrete Column type. </param>
    void definitions(string propertyName, object column)

    {

        if (propertyName == "Tags")

        {

            var tagCol = ((Column<string[]>)column);



            //        tagCol.TitleTemplate = s =>@

            //        <div @onclick:stopPropagation="true">

            //    <Input Placeholder="@column.title" AllowClear="true" @bind-Value="@column.search" OnChange="(e)=>OnInputClearChange(e,column.field)" TValue="string" />

            //</div>





            tagCol.CellRender = cellData =>
    @<span>
        @foreach (var tag in cellData.FieldValue)
    {
    var color = tag.Length > 5 ? "geekblue" : "green";
    if (tag == "loser")
    {
    color = "volcano";
    }
        <Tag Color="@color">@tag</Tag>
    }
    </span>;



            return;

        }



        // 已废弃

        // column.SetValue("Sortable", true);

        // column.SetValue("Filterable", true);

    }
}